<?php namespace Admin\Controller;
use Hdphp\Controller\Controller;
//品牌控制器
class BrandController extends CommonController{
	private $model;
	public function __auto(){
	    $this->model = new \Common\Model\Brand;
	}
	public function index(){
		//获取全部品牌数据
		$data = $this->model->get();
		//分配变量到页面
		View::with('data',$data);
		//载入页面
	    View::make();
	}
	//添加品牌
	public function add(){
		if(IS_POST){
			if($this->model->store()){
				View::success('添加成功',U('index'));
			}
			View::error($this->model->getError());
		}
	    View::make();
	}
	//编辑品牌
	public function edit(){
		if(IS_POST){
			if($this->model->edit()){
				View::success('编辑成功',U('index'));
			}
			View::error($this->model->getError());
		}
		$bid = Q('get.bid',0,'intval');
		$oldData = $this->model->where("bid={$bid}")->find();
		View::with('oldData',$oldData);
	    View::make();
	}
	//删除
	public function del(){
		$bid = Q('get.bid',0,'intval');
	    $this->model->where(array('bid'=>$bid))->delete();
		View::success('删除成功');
	}
}



 ?>